package app.server.project.main.service.controller.cms;

import app.server.project.core.http.CMSLstResp;
import app.server.project.core.http.RespModel;
import app.server.project.main.service.db.entity.cfg.*;
import app.server.project.main.service.dto.cms.RaceCfgDto;
import app.server.project.main.service.dto.recharge.TaskLangReq;
import app.server.project.main.service.service.cms.GlobalCfgService;
import app.server.project.main.service.service.lv.LvCfgService;
import app.server.project.main.service.service.race.RaceCfgService;
import app.server.project.main.service.service.rank.RankRewardCfgService;
import app.server.project.main.service.service.recharge.RechargeCfgService;
import app.server.project.main.service.service.task.TaskCfgService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@AllArgsConstructor
@RestController
@RequestMapping("/cmsapi")
@Slf4j
public class CMSCfgApiController {

    private GlobalCfgService globalCfgService;
    private LvCfgService lvCfgService;
    private RechargeCfgService rechargeCfgService;
    private RaceCfgService raceCfgService;
    private RankRewardCfgService rankRewardCfgService;
    private TaskCfgService taskCfgService;

    /**
     * 读取全部全局配置
     *
     * @return
     */
    @PostMapping("/getAllGlobalCfg")
    public CMSLstResp getAllGlobalCfg() {
        return this.globalCfgService.getAllGlobalCfg();
    }

    /**
     * 保存全局配置
     *
     * @param globalCfgEntity
     * @return
     */
    @PostMapping("/saveGlobalCfg")
    public RespModel saveGlobalCfg(@RequestBody GlobalCfgEntity globalCfgEntity) {
        this.globalCfgService.save(globalCfgEntity);
        return RespModel.success();
    }

    /**
     * 删除全局配置
     *
     * @param globalCfgEntity
     * @return
     */
    @PostMapping("/delGlobalCfg")
    public RespModel delGlobalCfg(@RequestBody GlobalCfgEntity globalCfgEntity) {
        this.globalCfgService.del(globalCfgEntity);
        return RespModel.success();
    }

    /**
     * 获取全部登记配置
     *
     * @return
     */
    @PostMapping("/getAllLvCfg")
    public CMSLstResp getAllLvCfg() {
        return this.lvCfgService.getAllCfg();
    }

    /**
     * 保存等级配置
     *
     * @return
     */
    @PostMapping("/saveLv")
    public RespModel saveLv(@RequestBody LvCfgEntity lvCfgEntity) {
        this.lvCfgService.save(lvCfgEntity);
        return RespModel.success();
    }

    /**
     * 删除等级配置
     *
     * @return
     */
    @PostMapping("/delLv")
    public RespModel delLv(@RequestBody LvCfgEntity lvCfgEntity) {
        this.lvCfgService.del(lvCfgEntity);
        return RespModel.success();
    }

    /**
     * 拉取全部充值界面
     *
     * @return
     */
    @PostMapping("/getAllRechargeCfg")
    public CMSLstResp<RechargeCfgEntity> getAllRechargeCfg() {
        return this.rechargeCfgService.getAll();
    }


    /**
     * 拉取商城界面
     *
     * @return
     */
    @PostMapping("/getStore")
    public CMSLstResp<RechargeCfgEntity> getStore() {
        return this.rechargeCfgService.getStore();
    }


    /**
     * 保存修改
     *
     * @return
     */
    @PostMapping("/saveRechargeCfg")
    public RespModel saveRechargeCfg(@RequestBody RechargeCfgEntity rechargeCfgEntity) {
        this.rechargeCfgService.save(rechargeCfgEntity);
        return RespModel.success();
    }

    /**
     * 拉取全部充值界面
     *
     * @return
     */
    @PostMapping("/editRechargeCfg")
    public RespModel editRechargeCfg(@RequestBody RechargeCfgEntity rechargeCfgEntity) {
        this.rechargeCfgService.edit(rechargeCfgEntity);
        return RespModel.success();
    }

    /**
     * 删除充值配置
     *
     * @return
     */
    @PostMapping("/delRechargeCfg")
    public RespModel delRechargeCfg(@RequestBody RechargeCfgEntity rechargeCfgEntity) {
        this.rechargeCfgService.del(rechargeCfgEntity);
        return RespModel.success();
    }

    /**
     * 获取全部赛道信息
     *
     * @return
     */
    @PostMapping("/getAllRaceCfg")
    public CMSLstResp<RaceCfgEntity> getAllRaceCfg() {
        return this.raceCfgService.getAll();
    }

    /**
     * 保存修改赛道配置
     *
     * @return
     */
    @PostMapping("/saveRaceCfg")
    public RespModel saveRaceCfg(@RequestBody RaceCfgDto buyEnergyCfgEntity) {
        this.raceCfgService.edit(buyEnergyCfgEntity);
        return RespModel.success();
    }

    /**
     * 编辑赛道信息
     *
     * @return
     */
    @PostMapping("/editRaceCfg")
    public RespModel editRaceCfg(@RequestBody RaceCfgDto buyEnergyCfgEntity) {
        this.raceCfgService.edit(buyEnergyCfgEntity);
        return RespModel.success();
    }

    /**
     * 删除赛道配置
     *
     * @return
     */
    @PostMapping("/delRaceCfg")
    public RespModel delRaceCfg(@RequestBody RaceCfgDto buyEnergyCfgEntity) {
        this.raceCfgService.del(buyEnergyCfgEntity);
        return RespModel.success();
    }

    /**
     * 获取排行榜配置
     *
     * @return
     */
    @PostMapping("/getAllRankRewardCfg")
    public CMSLstResp<RankRewardCfgEntity> getAllRankRewardCfg() {
        return this.rankRewardCfgService.getAllRankRewardCfg();
    }

    /**
     * 修改排行榜配置
     *
     * @param cfg
     * @return
     */
    @PostMapping("/addRankRewardCfg")
    public RespModel addRankRewardCfg(@RequestBody RankRewardCfgEntity cfg) {
        this.rankRewardCfgService.addRankRewardCfg(cfg);
        return RespModel.success();
    }

    /**
     * 编辑排行榜配置
     *
     * @param cfg
     * @return
     */
    @PostMapping("/editRankRewardCfg")
    public RespModel editRankRewardCfg(@RequestBody RankRewardCfgEntity cfg) {
        this.rankRewardCfgService.editRankRewardCfg(cfg);
        return RespModel.success();
    }

    /**
     * 修改排行榜配置
     *
     * @param cfg
     * @return
     */
    @PostMapping("/delRankRewardCfg")
    public RespModel delRankRewardCfg(@RequestBody RankRewardCfgEntity cfg) {
        this.rankRewardCfgService.delRankRewardCfg(cfg);
        return RespModel.success();
    }


    /**
     * 添加语言
     *
     * @param langCfgEntity
     */
    @PostMapping("/addLang")
    public RespModel addLang(@RequestBody LangCfgEntity langCfgEntity) {
        this.taskCfgService.addLang(langCfgEntity);
        return RespModel.success();
    }

    /**
     * 获取任务文案内容
     *
     * @param typeId
     * @return
     */
    @PostMapping("/getTaskLang")
    public CMSLstResp<LangCfgEntity> getTaskLang(TaskLangReq req) {
        var resp = this.taskCfgService.getLang(req.getLid());
        return resp;
    }

    /**
     * 删除文案
     *
     * @param langCfgEntity
     */
    @PostMapping("/delLang")
    public RespModel delLang(@RequestBody LangCfgEntity langCfgEntity) {
        this.taskCfgService.delLang(langCfgEntity);
        return RespModel.success();
    }

    /**
     * 根据任务类型获取任务明细
     *
     * @param typeId
     * @return
     */
    @PostMapping("/getTaskCfg")
    public CMSLstResp<TaskCfgEntity> getTaskCfg() {
        return this.taskCfgService.getTaskCfg();
    }

    /**
     * 添加任务配置
     *
     * @param taskCfgEntity
     * @return
     */
    @PostMapping("/addTaskCfg")
    public RespModel addTaskCfg(@RequestBody TaskCfgEntity taskCfgEntity) {
        this.taskCfgService.addTaskCfg(taskCfgEntity);
        return RespModel.success();
    }

    /**
     * 编辑任务配置
     *
     * @param taskCfgEntity
     */
    @PostMapping("/editTaskCfg")
    public RespModel editTaskCfg(@RequestBody TaskCfgEntity taskCfgEntity) {
        this.taskCfgService.editTaskCfg(taskCfgEntity);
        return RespModel.success();
    }

    /**
     * 删除任务
     *
     * @param taskCfgEntity
     */
    @PostMapping("/delTaskCfg")
    public RespModel delTaskCfg(@RequestBody TaskCfgEntity taskCfgEntity) {
        this.taskCfgService.delTaskCfg(taskCfgEntity);
        return RespModel.success();
    }


}
